package com.gin.no_gay_alliance.activity;

import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;

import androidx.appcompat.widget.Toolbar;

import com.gin.jackson.utils.ObjectUtils;
import com.gin.no_gay_alliance.databinding.AcvitivySourceCodeBinding;
import com.gin.no_gay_alliance.exception.RequireParamException;

/**
 * 源代码活动
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/14 14:26
 **/
public class SourceCodeActivity extends BaseBindingActivity<AcvitivySourceCodeBinding> {
    private static final String ARG_KEY = "CODE";
    private String code;

    /**
     * 解析意图
     *
     * @param intent 意图
     */
    @Override
    protected void handleIntent(Intent intent) {
        code = intent.getStringExtra(ARG_KEY);
        if (ObjectUtils.isEmpty(code)) {
            throw new RequireParamException();
        }
    }

    /**
     * onCreate中的后续操作
     */
    @Override
    protected void onCreate() {
        b.tv.setText(code.replace("<br>", "\n").replace("<br/>", "\n"));
    }

    /**
     * 装载右上角菜单
     *
     * @param menu         菜单
     * @param menuInflater 菜单渲染器
     */
    @Override
    protected void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {

    }

    @Override
    protected Toolbar initToolbar() {
        return b.toolbar;
    }

    /**
     * 启动活动
     *
     * @param context 上下文
     * @param code    源代码
     */
    public static void startActivity(Context context, String code) {
        Intent intent = new Intent(context, SourceCodeActivity.class);
        intent.putExtra(ARG_KEY, code);
        intent.putExtra(BaseBindingActivity.INTENT_KEY_TITLE, "源码");
        context.startActivity(intent);
    }
}
